﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace movieplayer
{
    public partial class Form1 : Form
    {
        double totalframe;
        int state=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
                axWindowsMediaPlayer1.Ctlcontrols.pause();
               
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.settings.autoStart = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
          

        }

        private void axWindowsMediaPlayer1_PositionChange(object sender, AxWMPLib._WMPOCXEvents_PositionChangeEvent e)
        {
            label1.Text =axWindowsMediaPlayer1.Ctlcontrols.currentPositionString;
            
        }

        private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            if ((WMPLib.WMPPlayState)e.newState == WMPLib.WMPPlayState.wmppsPaused)
                label1.Text = "暂停";
           // if ((WMPLib.WMPPlayState)e.newState == WMPLib.WMPPlayState.wmppsPlaying) label1.Text = axWindowsMediaPlayer1;
          //     trackBar1.Value = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (axWindowsMediaPlayer1.currentMedia.duration == 0)label1.Text = "正在载入"; 
            
            if (axWindowsMediaPlayer1.currentMedia.duration != 0)
            {
                if (state == 0)
                {
                    axWindowsMediaPlayer1.Ctlcontrols.play();
                    totalframe = axWindowsMediaPlayer1.currentMedia.duration;
                    label1.Text = axWindowsMediaPlayer1.currentMedia.durationString;
                    trackBar1.Maximum = (int)totalframe;
                   // timer1.Enabled = false;
                    state = 1;
                }
                if(state ==1)
                {
                    trackBar1.Value = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
                }
            }
        }
    }
}
